package com.ruoyi.service.jpjs.proprogress.impl;


import com.ruoyi.mapper.jpjs.proprogress.ProProgressMapper;
import com.ruoyi.service.jpjs.PublicService;
import com.ruoyi.service.jpjs.proprogress.ProProgressService;
import com.ruoyi.util.BaseResult;
import com.ruoyi.util.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service
public class ProProgressServiceimpl implements ProProgressService {

    @Autowired
    ProProgressMapper proProgressMapper;

    @Autowired
    PublicService publicService;

    @Override
    public List<Map<String, Object>> list(Map map) {
        List<Map<String, Object>> compList = publicService.findUserCompAndJszb();
        map.put("compList", compList);
        return proProgressMapper.list(map);
    }

    @Override
    public BaseResult findPersonNumByTotalArea(Double total_area) {
        String totalArea = "";
        if (total_area < 100000) {
            totalArea = "小于十万平米";
        } else if (total_area >= 100000 && total_area < 150000) {
            totalArea = "十万到十五万平米";
        } else if (total_area >= 150000 && total_area < 200000) {
            totalArea = "十五万到二十万平米";
        } else if (total_area >= 200000 && total_area < 250000) {
            totalArea = "二十到二十五万平米";
        } else if (total_area >= 250000 && total_area < 300000) {
            totalArea = "二十五到三十万平米";
        } else if (total_area >= 300000 && total_area < 350000) {
            totalArea = "三十到三十五万平米";
        } else if (total_area >= 350000 && total_area < 400000) {
            totalArea = "三十五到四十万平米";
        } else if (total_area >= 400000) {
            totalArea = "四十万以上";
        }
        Map map = proProgressMapper.findPersonNumByTotalArea(totalArea);
        if (total_area > 400000) {
            //算出超出
            double goBeyond = total_area - 400000;
            //算出要加几个人
            double goBeyondPerSonNum = Math.floor(goBeyond / 100000);
            map.put("aqy", 2 + (int) goBeyondPerSonNum);
            map.put("yjsgy", 10 + (int) goBeyondPerSonNum);
            map.put("erjsgy", 10 + (int) goBeyondPerSonNum);
            map.put("sjsgy", 10 + (int) goBeyondPerSonNum);
            int hj = Integer.parseInt(map.get("aqy").toString()) + Integer.parseInt(map.get("yjsgy").toString())
                    + Integer.parseInt(map.get("erjsgy").toString()) + Integer.parseInt(map.get("sjsgy").toString());
            map.put("hj", hj);
        }
        return BaseResult.build(ResultEnum.SUCCESS, map);
    }

    @Override
    public int add(Map map) {
        return proProgressMapper.add(map);
    }

    @Override
    public Map<String, Object> findDataById(String id) {
        return proProgressMapper.findDataById(id);
    }

    @Override
    public int edit(Map map) {
        return proProgressMapper.edit(map);
    }
}
